function getCookie(name) {
	var x = document.cookie.match("\\b" + name + "=([^;]*)\\b");
	return x ? x[1]:undefined;
}

$(document).ready(function(){
	$("#check_username").click(function(){
		var user = $("#username").val();
		var json_str = {"username": user, "_xsrf": getCookie("_xsrf")};
		$.ajax({
			type:"post",
			url:"/exists_or_not",
			data:json_str,
			cache:false,
			success:function(data){
				$("#username_notice").text(data);
			},
			error:function(){
				alert("连接服务器失败！");
			},
		});
	});

	$("#login").click(function(){
		var user = $("#username").val();
		var pwd = $("#password").val();
		var json_str = {"username": user, "password": pwd};
		$.ajax({
			type:"post",
			url:"/allow_login",
			data:json_str,
			cache:false,
			success:function(data){
				if(data=='0') {
					window.location.href='/';
				} else {
					$("#login_notice").text(data);
				}
			},
			error:function(){
				alert("连接服务器失败！");
			},
		});
	});



});